﻿#ifndef NSSHARE_UTILS_ARRAY_H_
#define NSSHARE_UTILS_ARRAY_H_

#include <memory.h>


namespace nsshare
{
namespace utils
{

template<typename T, size_t count>
class FixedArray
{
public:
    void Fill(T val)
    {
        for(auto i = 0; i < count; ++i)
            elements_[i] = val;
    }

    operator T * ()
    {
        return elements_;
    }

    operator const T * () const
    {
        return elements_;
    }

private:
    T elements_[count];
};

template<typename T>
class ScopeArray
{
public:
    ScopeArray()
    {
        array_ = 0;
    }

    ~ScopeArray()
    {
        fini();
    }

    bool init(size_t size)
    {
        fini();
        array_ = new(std::nothrow) T[size];
        return array_?true:false;
    }

    void fini()
    {
        if(array_)
        {
            delete array_;
            array_ = 0;
        }
    }

    operator T * ()
    {
        return array_;
    }

private:
    T * array_;
};

}
}

#endif